package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.StrategyReplyUserComment;
import cn.wolfcode.trip.base.domain.StrategyUserComment;
import cn.wolfcode.trip.base.query.StrategyUserCommentQuery;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategyUserCommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** lituan
 * 攻略点评资源控制器
 */

@RestController
@RequestMapping("/strategyComments")
public class StrategyCommentController {

    @Autowired
    private IStrategyCommentService commentService;

    @Autowired
    private IStrategyUserCommentService userCommentService;
    /**
     * lituan
     * 查出所有热门的点评
     * @param state
     * @return
     */
    @GetMapping("/{state}")
    public List<StrategyComment> selectHotComment(@PathVariable Long state){
        List<StrategyComment> commentList=commentService.selectHotComment(state);
        return commentList;
    }

    /**
     * lituan
     * 根据点评id 查出该点评
     * @param id
     * @return
     */
    @GetMapping
    public StrategyComment getCommentById(Long id){
        StrategyComment comment=commentService.getCommentById(id);
        return comment;
    }


    /**
     * lituan
     * 查出指定点评下的评论
     * @param qo
     * @return
     */
    @GetMapping("/{strategyCommentId}/strategyUserComments")
    public PageInfo<StrategyUserComment> query(StrategyUserCommentQuery qo){
        return userCommentService.selectByStrategyCommentId(qo);
    }

    /**
     * lituan
     * 添加评论
     */
    @PostMapping("/{strategyComment.id}/strategyUserComment")
    public JSONResult saveUserComment(StrategyUserComment userComment){
        JSONResult jsonResult= new JSONResult();
        try {
            userCommentService.saveUserComment(userComment);
        } catch (Exception e) {
            jsonResult.mark("提交失败,稍后再试");
            e.printStackTrace();
        }
        return jsonResult;
    }


}
